package com.migo.service.impl;

import com.migo.dao.UserinfoInternationDao;
import com.migo.entity.UserinfoInternationEntity;
import com.migo.service.UserinfoInternationService;
import com.migo.utils.DateUtils;
import com.migo.utils.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("userinfoInternationService")
public class UserinfoInternationServiceImpl implements UserinfoInternationService {
    @Autowired
    private UserinfoInternationDao userinfoInternationDao;

    @Override
    public UserinfoInternationEntity queryObject(Integer id) {
        return userinfoInternationDao.queryObject(id);
    }

    @Override
    public List<UserinfoInternationEntity> queryList(Map<String, Object> map) {
        return userinfoInternationDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return userinfoInternationDao.queryTotal(map);
    }

    @Override
    public void save(UserinfoInternationEntity userinfoInternation) {
        userinfoInternationDao.save(userinfoInternation);
    }

    @Override
    public void update(UserinfoInternationEntity userinfoInternation) {
        userinfoInternationDao.update(userinfoInternation);
    }

    @Override
    public void delete(Integer id) {
        userinfoInternationDao.delete(id);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        userinfoInternationDao.deleteBatch(ids);
    }

    @Override
    public UserinfoInternationEntity phoneLogin(Map<String, String> map) {
        return userinfoInternationDao.phoneLogin(map);
    }

    @Override
    public UserinfoInternationEntity emailLogin(Map<String, String> map) {
        return userinfoInternationDao.emailLogin(map);
    }

    @Override
    public void modiyPassword(String userId, String newPassword) {
        userinfoInternationDao.modiyPassword(userId, newPassword);
    }

    @Override
    public UserinfoInternationEntity queryUser(String userId) {
        return userinfoInternationDao.queryUser(userId);
    }

    @Override
    public UserinfoInternationEntity userLogOut(String userId) {
        return null;
    }

    @Override
    public UserinfoInternationEntity queryUserExist(Map<String, String> map) {
        return userinfoInternationDao.queryUserExist(map);
    }

    @Override
    public void register(Map<String, String> params) {
        String password = params.get("password");
        //sha256加密
//		password = new Sha256Hash(password).toHex();
        //保留version+ 第一版需求
        password = MD5.encrypt(password);
        String nickname = params.get("nickname");
        String country = params.get("country");
        String email = params.get("email");
        String mobile = params.get("mobile");
        String uuid = params.get("uuid");
        String ip = params.get("ip");
        String deviceType = params.get("deviceType");
        String version = params.get("version");
        UserinfoInternationEntity eUser = new UserinfoInternationEntity();
        eUser.setUseremail(email);
        eUser.setDeviceType(deviceType);
        eUser.setPassword(password);
        eUser.setNickname(nickname);
        eUser.setCountry(country);
        eUser.setUserphone(mobile);
        eUser.setUserReqIp(ip);
        eUser.setUserid(uuid);
        eUser.setAddtime(DateUtils.getNow());
        eUser.setVersion(version);  //代表 APP版本
        eUser.setTemp("0");  //代表 APP注册
        userinfoInternationDao.register(eUser);
    }

    @Override
    public void register(UserinfoInternationEntity user) {
        userinfoInternationDao.register(user);
    }

}
